<template>
  <div>
    <!-- 顶部标签导航 -->
    <div class="tag">
      <van-tabs v-model="activeName" @click="fun">
        <van-tab v-for="(v, k) in brotherCategory" :key="k" :title="v.name">
          <div class="title">
            <!-- <h1>{{ v.id }}</h1> -->
            <h1>{{ v.name }}</h1>
            <h5>{{ v.front_desc }}</h5>
          </div>
        </van-tab>
      </van-tabs>
    </div>
    <!-- 商品 -->
    <van-grid :border="false" :column-num="2">
      <van-grid-item v-for="(v, k) in goodsList" :key="k">
        <van-image :src="v.list_pic_url" />
        <p class="p1">{{ v.name }}</p>
        <p class="p2">{{ v.retail_price.toFixed(2) }}</p>
      </van-grid-item>
    </van-grid>
  </div>
</template>

<script>
import { GetHomeKind, GetTipList, GetTypeList } from "@/request/api";
export default {
  data() {
    return {
      brotherCategory: [],
      activeName: "",
      goodsList: [], //商品列表
      val: "",
      array: [],
      id: [],
      //   currentCategory: [],
    };
  },
  methods: {
    fun(value) {
      GetTipList({ categoryId: this.array[value], page: 1, size: 1000 }).then(
        (res) => {
          console.log(res);
          let { goodsList } = res.data;
          this.goodsList = goodsList;
        }
      );
    },
  },
  created() {
    this.val = this.$route.query.id;
    // console.log(this.$route.query.id);
    // 首页分类区块标题栏
    GetHomeKind({ id: this.val }).then((res) => {
      let { brotherCategory, currentCategory } = res.data;
      this.currentCategory = currentCategory;
      this.activeName = currentCategory.name;
      this.brotherCategory = brotherCategory;
      brotherCategory.forEach((e) => {
        this.array.push(e.id);
        // console.log(this.arr);
      });
      //   console.log(res.data);
    });
    // 首页分类区块内容
    GetTipList({ categoryId: this.val, page: 1, size: 1000 }).then((res) => {
      //   console.log(res);
      let { goodsList } = res.data;
      this.goodsList = goodsList;
    });
    // 请求分类页面数据 左侧边栏
    GetTypeList().then((res) => {
      console.log(res);
      res.data.categoryList.forEach((item, index) => {
        this.id.push(item.id);
        console.log(this.id);
        this.id.forEach((e, ins) => {
          if (e == this.val) {
            this.activeName = ins;
          }
        });
      });
    });
  },
};
</script>

<style lang="less">
// .new {
//   background-color: #fff;
//   height: 5rem;
h1 {
  height: 0.4rem;
  line-height: 0.4rem;
  text-align: center;
  font-size: 0.18rem;
}
h5 {
  height: 0.4rem;
  line-height: 0.4rem;
  text-align: center;
  font-size: 0.14rem;
}
.title {
  background-color: #efefef;
}
.p1 {
  font-size: 0.13rem;
  color: #333333;
}
.p2 {
  padding-top: 0.1rem;
  color: #8b0000;
  font-size: 0.12rem;
}
//   .new_img {
//     float: left;
//   }
//   img {
//     width: 1.8rem;
//   }
//   .new_content {
//     text-align: center;
//     .p1 {
//       font-size: 0.13rem;
//       color: #333333;
//     }
//     .p2 {
//       padding-top: 0.1rem;
//       color: #8b0000;
//       font-size: 0.12rem;
//     }
//   }
// }
</style>